
var mask = null;
var s_name = '';
var s_id = '';
var tc_id = null;
var old_back = mui.back;
var coursepay = '';
var select_id = '';
var schoolid = '';
mui.plusReady(function(){
	mui.init();
	mask = mui.createMask();//遮罩层
	var self = plus.webview.currentWebview();

	self.setStyle({'popGesture':'none'});
	tc_id = self.tc_id;
	select_id = self.select_id;
	schoolid = self.schoolid
	mui.back = function() {
		getCoursename();
	    var target = plus.webview.getWebviewById('pxfw_xy_from.html');
	    mui.fire(target, 'select_dkmcEvent', {s_name:s_name,s_id : s_id,coursepay : coursepay});
	    old_back();
	};    
	
	setTimeout(function(){
		loadDkmc();
	},500)
});

var type = null;
$(function() { // 初始化内容
	mui.plusReady();
	mask = mui.createMask(); //遮罩层
	mui.init();
	tap_init();

	login_user = JSON.parse(localStorage.getItem('loginUser'));
	type = sessionStorage.getItem("courseType")
	datetime_init();

	getCoursename();
})



var app = new Vue({
	el : '#app',
	data : {
		show : true,
		todos : []
	},
	methods : {

	}
});

function getCoursename(){
	jQuery("input:checkbox[name='coursename']:checked").each(function() {
  		s_id = s_id + jQuery(this).val().split('-')[0] + ',';
  		s_name = s_name + jQuery(this).val().split('-')[1] + ',';  	
  		coursepay = coursepay + jQuery(this).val().split('-')[2] + ',';
	});
	s_id = s_id.substring(0,s_id.lastIndexOf(','));
	s_name = s_name.substring(0,s_name.lastIndexOf(','));
	coursepay = coursepay.substring(0,coursepay.lastIndexOf(','));
}

function loadApp(data){
	var arry = new Array();
    for (var i = 0 ; i < data.length ; i++){
      var d = data[i];
      var o = new Object();
      o.id = d.id + "-" + d.coursename + "-" +d.coursepay;
      o.coursename = d.coursename;
      if(select_id.indexOf(d.id + "-" + d.coursename) != -1){
      	o.ischeck = "checked";
      }else{
      	o.ischeck = false;
      }
      arry.push(o);
    }
    console.log(JSON.stringify(arry));
    app.todos = arry;

}


function getCourse(type){
	var data = {};
	data['stuid'] = stu_id;
	data['type'] = type;
	jQuery.ajax({
		type: "post",
		headers: {
			'Authorization': login_user.token
		},
		url: serverip + "newxlc_course/loadNewxlc_courses",
		contentType: 'application/json;charset=UTF-8',
		data: JSON.stringify(data),
		dataType: "json",
		timeout: 10000,
		beforeSend: function() {
			mask.show(); //显示遮罩层	
		},
		success: function(res) {
			mask.close(); //显示遮罩层 	  
			console.log("课程信息=====" + JSON.stringify(res));
			
			loadApp(res.courses);	    		
		},
		error: function(e) {
			console.log("错误信息====" + JSON.stringify(e));
			mask.close(); //显示遮罩层
			var msg = e.responseJSON.message;
			var code = e.responseJSON.status;
			mui.alert('错误编码' + code + "\n" + "错误信息:" + msg);
			console.log("错误信息====" + JSON.stringify(e));
		}
	});
	
}


